#ifndef BCITARGETSGROUP_H
#define BCITARGETSGROUP_H

#include <QObject>
#include <QPainter>

#include <QUuid>
#include <unordered_map>

#include "qbcitargetinterface.h"

struct QUuidHash {
  std::size_t operator()(const QUuid &id) const { return qHash(id); }
};

class QBciTargetsGroup : public QObject {
  Q_OBJECT
public:
  explicit QBciTargetsGroup(QObject *parent = nullptr);

  void addTarget(QBciTargetInterface *target);

  void removeTarget(QBciTargetInterface *target);
  void removeTarget(const QString &label);

  QBciTargetInterface *getTarget(const QString &label);
  QBciTargetInterface *operator[](const QString &label);

  void paint(QPainter *painter);

public slots:
  void setTarget(QBciTargetInterface *target);
  void setTarget(const QString &targetLabel);
  void setTarget(QBciTargetInterface *target, int timeout);
  void setTarget(const QString &targetLabel, int timeout);
  void setEnableWave(const bool &flag);

  void resetTarget(QBciTargetInterface *target);
  void resetTarget(const QString &targetLabel);
  void setAllTarget();
  void resetAllTarget();

signals:
  void update();

private:
  QList<QBciTargetInterface *> TargetList;
  void startTimer(QBciTargetInterface *target, int timeout);
  void endTimer(const QUuid &id);
  std::unordered_map<QUuid, QSharedPointer<QTimer>, QUuidHash> timerMap;

};
#endif // BCITARGETSGROUP_H
